package com.pay.controller;

import com.pay.bo.NotifyMerchantBO;
import com.pay.service.Impl.PayMessageTemplateServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.concurrent.ExecutionException;

/**
* 该类是为测试类并非正式代码
* 仅供测试
*/
@RestController
public class WeChatTemplateController {
    @Autowired
    private PayMessageTemplateServiceImpl payMessageTemplateServiceImpl;
    
    /**
     * 测试代码
     */
    @GetMapping("/testSend")
    public String testSend(String merchantId,
                           String merchantOpenId,
                           BigDecimal paymentAmount,
                           @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date payDate,
                           String paymentChannel, String paymentId) throws ExecutionException, InterruptedException {
        payMessageTemplateServiceImpl.notifyMerchantPaymentResultThread(
                new NotifyMerchantBO(merchantId,
                        merchantOpenId,
                        paymentAmount,
                        payDate,
                        paymentChannel,
                        paymentId)
        );
        return "ok";
    }
    
    /**
     * 测试代码
     */
    @GetMapping("/testSend1")
    public String testSend1(String merchantId,
                           String merchantOpenId,
                           BigDecimal paymentAmount,
                           @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date payDate,
                           String paymentChannel, String paymentId) throws ExecutionException, InterruptedException {
        payMessageTemplateServiceImpl.notifyMerchantPaymentResultBatchMQ(
                new NotifyMerchantBO(merchantId,
                                    merchantOpenId,
                                    paymentAmount,
                                    payDate,
                                    paymentChannel,
                                    paymentId)
        );
        return "ok";
    }
}